/*eslint-disable*/
import { ElMessage } from "element-plus";
import pubsub from "pubsub-js";
import mainApi from "@/api/mainApi";

export default {
    // 路径验证
    PathValidation() {
        mainApi.readJson(ElMessage, (data) => {
            let fs = window.myApi.fs;
            let pathList = [
                { name: "文件仓库", path: data.fileHouse },
                { name: "waigua路径", path: data.waigua },
            ];
            // console.log(pathList);

            for (let index = 0; index < pathList.length; index++) {
                const element = pathList[index];
                fs.access(element.path, fs.constants.F_OK, (err) => {
                    // 路径不存在
                    if (err) {
                        ElMessage({
                            message: `${element.name}路径不存在！`,
                            type: "error",
                            duration: 10000,
                        });
                        pubsub.publish("routerChange", {
                            targetComponent: "setup",
                            linkName: "setup",
                            componentName: "setup",
                            origin_nav: "setup",
                            isNav: true,
                        });
                        pubsub.publish("moduleSelect", { target: "setup" });
                        return
                    }
                });
            }
        });
    }
}